import java.util.ArrayList;
import java.util.Date;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Statistic statistics= new Statistic();
        Scanner scanner = new Scanner(System.in);

        while (true) {
            System.out.println("请选择操作：");
            System.out.println("1. 记录网页访问");
            System.out.println("2. 显示访问量排行榜");
            System.out.println("3. 统计总访问量");
            System.out.println("4. 计算平均访问量");
            System.out.println("5. 显示页面最后访问时间");
            System.out.println("6. 清空访问统计");
            System.out.println("7. 退出");

            int choice = scanner.nextInt();

            switch (choice) {
                case 1:
                    System.out.println("请输入要访问的页面URL:");
                    String url = scanner.next();
                    statistics.recordPageVisit(url);
                    break;
                case 2:
                    System.out.println("访问量排行榜:");
                    statistics.VisitRank();
                    break;
                case 3:
                    int total = statistics.calculateTotalVisitCount();
                    System.out.println("总访问量: " + total);
                    break;
                case 4:
                    double average = statistics.calculateAverageVisitCount();
                    System.out.println("平均访问量: " + average);
                    break;
                case 5:
                    System.out.println("请输入要查询最后访问时间的页面URL:");
                    url = scanner.next();
                    java.util.Date lastVisitTime = statistics.getLastVisitTime(url);
                    if (lastVisitTime!= null) {
                        System.out.println("该页面的最后访问时间: " + lastVisitTime);
                    } else {
                        System.out.println("页面未找到");
                    }
                    break;
                case 6:
                    statistics.clearStatistics();
                    System.out.println("已清空访问统计");
                    break;
                case 7:
                    return;
                default:
                    return;
            }
        }

    }
}
